﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 版权所有 (c) 2022   保留所有权利。
 * CLR版本：4.0.30319.42000
 * 机器名称：DESKTOP-UL84BU5
 * 公司名称：
 * 命名空间：KingerRobot.WanliMDC.SpiService.Services.BaseBussiness
 * 唯一标识：021fcc02-e744-4a32-b750-d297a965f26b
 * 文件名：MaterialImpl
 * 当前用户域：DESKTOP-UL84BU5
 * 
 * 创建者：zzl
 * 电子邮箱：1003590782@qq.com
 * 创建时间：2022/6/8 14:05:33
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System.Threading.Tasks;

namespace KingerRobot.MexicoSailunMDC.SpiService;
[Logging]
public class MaterialImpl : IMaterialService
{
    private readonly static IProdMaterial _ProdMaterial = new BProdMaterial();
    private readonly static IWcsEquipLocHold _WcsEquipLocHold = new BWcsEquipLocHold();
    private readonly static ITask _Task = new BTask();
    private readonly static IWmsSetting _WmsSetting = new BWmsSetting();
    public int MesSyncMaterial(MaterialMDCInfo materialMDCInfo)
    {
        return _ProdMaterial.RefreshMaterial(materialMDCInfo);
    }
    public List<WcsWarehouseCrnMaterialInfo> WscSyncWarehouseMaterial()
    {
        return _WcsEquipLocHold.WscSyncWarehouseMaterial();
    }
    public void UpdateWarehouseMaterial(List<WcsWarehouseCrnMaterialInfo> wcsWarehouseCrnMaterialInfos)
    {
        _WcsEquipLocHold.UpdateWarehouseMaterial(wcsWarehouseCrnMaterialInfos);
    }
    public SpareMaterialInfo GetSpareMaterialInfo(int taskNo)
    {
        var spareMater = new SpareMaterialInfo();
        var task = _Task.GetTaskByTaskNo(taskNo);
        if (task != null)
        {
            var mater = _ProdMaterial.GetMaterialBySkuId(task.SkuId.GetValueOrDefault());
            spareMater = new SpareMaterialInfo
            {
                Spec = mater?.Spec,
                Height = mater?.MaterialHeight,
                Inside = mater?.InsideDiameter,
                Outside = mater?.OutsideDiameter
            };
        }
        return spareMater;
    }

    public int GetHeightTypeBySku(long skuId)
    {

        _ = int.TryParse(_WmsSetting.GetWmsSettingByCode(ConstFields.MaterialHeightSideType).Value, out var height);
        var material = _ProdMaterial.GetMaterialBySkuId(skuId);
        WriteLog($"下传位高度记录 sku-{skuId},height-{height},MaterialHeight-{material.MaterialHeight}", true);
        var heightType = material.MaterialHeight >= height ? 1 : 0;
        return heightType;
    }

    public List<StockMaterialCodeNumBean> GetStockMaterialCodeAndNum()
    {
        var result = _ProdMaterial.GetStockMaterialCodeAndNum();

        return result;

    }
}
